package sky.com.util
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import mx.core.FlexGlobals;
	import mx.controls.Alert;

	public class LabelFactory
	{
		private static var labelInstance:LabelFactory;
		private static var myXml:XML=new XML();
		private static var xmlUrl:String="labels.xml";
		private static var urlRequest:URLRequest=new URLRequest(xmlUrl);
		private static var urlLoader:URLLoader;
		
		public function LabelFactory()
		{
			
			if(urlLoader==null){
				
				urlLoader=new URLLoader(urlRequest);
				urlLoader.addEventListener(Event.COMPLETE,loadXMLComplete);
				urlLoader.addEventListener(IOErrorEvent.IO_ERROR,loadXMLError);
			}
		}
		
		public static function getLabelInstance():LabelFactory{
			if(labelInstance==null){
				labelInstance=new LabelFactory();
			}
			return labelInstance;
		}
		
		public function getLabel(labelStr:String):String{
			//Alert.show("11");
			return myXml.child(labelStr);
		}
		
		private static function loadXMLComplete(event:Event):void{
			myXml=XML(urlLoader.data);
			//Alert.show(myXml.child("label1"));
			FlexGlobals.topLevelApplication.loadLabelXMLComplete();
		}
		
		private static function loadXMLError(event:Event):void{
			Alert.show("读取labels.xml文件失败");
		}
	}
}